package thread;
/**
 * 中断线程
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread wkq = new Thread("吴克勤"){
            public void run(){
                System.out.println(getName()+"休息一会儿");
                System.out.println("Zzzz...");
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    System.out.println("谁呀!谁呀!谁呀!");
                }
                System.out.println(getName()+"醒了");
            }
        };

        Thread fbb = new Thread("范冰冰"){
            public void run(){
                System.out.println(getName()+"问:中午去哪儿吃饭呢?");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(getName()+":问问吴克勤吧!");
                wkq.interrupt();//中断睡眠, 触发wkq线程的InterruptedException异常
            }
        };
        wkq.start();
        fbb.start();
    }
}
